package com.job.meituan;

import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * @ClassName: test.Meituan5
 * @Description:
 * @Author: 12071
 * @Date: 2022/4/9 17:35
 */
public class Meituan0409_5 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] input = new int[n];
        StringBuffer sb1 = new StringBuffer();
        for(int i=0;i<n;i++){
            //input[i] = sc.nextInt();
            sb1.append(sc.nextInt());
        }
        int m= sc.nextInt();
        int[] input2 = new int[n];
        StringBuffer sb2 = new StringBuffer();
        for(int i=0;i<n;i++){
            //input2[i] = sc.nextInt();
            sb2.append(sc.nextInt());
        }
        int max =0;
        int[] tmp=new int[3];
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                String str = sb1.substring(i,j);
                int t = sb2.indexOf(str);
                if(t!=0 && j-i+1>max){
                    tmp[0] = i;
                    tmp[1] = t;
                    tmp[2] = j-i+1;
                    max=j-i+1;
                }
            }
        }
        System.out.println(max);
        int res = 0;
        if(tmp[0]>0 || tmp[1]+tmp[2]>m) res = m+n;
        else{
            res = (n-tmp[2])+(m-tmp[2]);
        }
        System.out.println(res);
    }
}
